#ifndef MOCHA_DETAIL_SHARED_LIBRARY_HPP_INCLUDED
#define MOCHA_DETAIL_SHARED_LIBRARY_HPP_INCLUDED

/**
 * @file 
 */

#include <string>
#include <boost/filesystem.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>

namespace mocha {
/**
 * Shared library.
 * Loads symbols (functions, etc.) by name and returns their addresses.
 */
class shared_library : public boost::noncopyable {
public:
	~shared_library();
	/**
	 * Opens a shared object/library file.
	 * @param file File to open.
	 * @return 
	 */
	static boost::shared_ptr<shared_library> open(const boost::filesystem::path& file);
	/**
	 * 
	 * @param name Name of the symbol.
	 * @return Pointer to the symbol or null if it cannot be found.
	 */
	void* symbol(const std::string& name);
private:
	shared_library(void* lib);
	/**
	 * Closes the associated file and releases all symbols.
	 */
	void close();
	/// Library handle.
	void* lib_;
};
}

#endif

